package ModelLayer;
import java.util.ArrayList;

/**
 * Write a description of class AddressBook here.
 * 
 * @author (Danny Melsen) 
 * @version (06-11-12)
 */
public class AddressBook
{
    // instance variables - replace the example below with your own
    private ArrayList<Person> persons;

    /**
     * Constructor for objects of class AddressBook
     */
    public AddressBook()
    {
        persons = new ArrayList<Person>();
    }

    /**
     * Add Person to the AddressBook
     */
      public void addPerson(Person person)
    {
    if (persons.contains(person)) {
                System.out.println ("The person is already on the list"); 
            }
            else {
        persons.add(person);
    }
    }
    
    /**
     * Finding a person in the AddressBook by id
     */
    public Person findPerson(long id)
    {
        for (Person person : persons) {
            if (person.getId() == id) {
            }
            return person;
        }
        return null;
    }
    /**
     * Update person in the addressbook
     */
    public void updatePerson(long id, String address, String city, String name,
                               String phone, String postalCode)
    {
        for (Person person : persons) {
            if (person.getId() == id) {
            }
            person.setAdress(address);
            person.setCity(city);
            person.setId(id);
            person.setName(name);
            person.setPhone(phone);
            person.setPostalCode(postalCode);
        }

        }

    
    /**
     * delete a person in the addressbook
     */
    public void deletePerson(Person person)
    {
        persons.remove(person);
    }
    
    /**
     * List of all persons in the Addressbook
     */
    public void listOfAllPersons()
    {
        for ( Person person : persons ) {
            person.printInformationPerson();
        }
        
    }

    
}

